#1 自定义函数
def get_sum1(num1): # num1是形式参数
    sum2 = 0
    for i1 in range(1, num1+1):
        sum2 += i1
    print(f'1到{num1}之间的累加和为：{sum2}')

#2 函数的调用
get_sum1(10)    # 10是实际参数
get_sum1(55)    # 55是实际参数

#3 函数的参数传递
def happy_birthday(name, age):
    print('祝' + name + '，' + str(age) + '岁生日快乐')

# 位置参数
happy_birthday('zw', 18)

# 关键字传参
happy_birthday(age = 18, name = 'zw')
happy_birthday('zw', age = 18)
#happy_birthday(name = 'zw', 18) # 报错，语法错误（位置参数在前，关键字参数在后）

# 默认值参数
def happy_birthday1(name1 = 'zw', age1 = 18):
    print('祝' + name1 + '，' + str(age1) + '岁生日快乐')

happy_birthday1()
happy_birthday1(age1 = 24)

#def happy_birthday2(name2 = 'zw',  18): # 报错，语法错误（位置参数在前，关键字参数在后）

# 可变参数
#a 个数可变的位置参数
def fun1(*para1):
    print(type(para1))
    for item1 in para1:
        print(item1)

fun1(10, 20, 30)
fun1([10, 20, 30]) # 一个参数，参数类型为列表
fun1(*[10, 20, 30]) # 列表解包

#b 个数可变的关键字参数
def fun2(**kwpara2):
    print(type(kwpara2))
    for key2, value2 in kwpara2.items():
        print(key2, '---', value2)

fun2(name = 'zw', age = 18, heigh = 170)

d2 = {'name': 'zw', 'age': 18, 'heigh': 170}
fun2(**d2)  # 字典解包

#4 函数的返回值
def multi(x1, x2):
    return x1 * x2

print(multi(2, 3))
print(multi(multi(2, 3), 5))

# 多个返回值
def my_sum(num_max):
    sum_all = 0
    sum_odd = 0
    sum_even = 0
    for i1 in range(1, num_max + 1):
        if i1 % 2 == 1:
            sum_odd += i1
        else:
            sum_even += i1
        sum_all += i1
    return sum_all, sum_odd, sum_even

my_result = my_sum(10)
print(my_result, type(my_result))

# 系列解包赋值
a, b, c = my_sum(10)
print(a, b, c)